package com.gxa.controller;

import com.github.pagehelper.PageHelper;
import com.gxa.dto.ResultData;
import com.gxa.pojo.GoodsType;
import com.gxa.service.GoodsTypeService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author:IT-CNLM
 * @date:Created at 2020/07/27
 */
@Api(tags = "商品分类管理")
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;


    @ApiOperation("分类列表")
    @GetMapping("/list")
    public ResultData list(@RequestParam(defaultValue = "1") Integer pageNo){

        Integer limit = 10;
        PageHelper.startPage(pageNo, limit);
        return goodsTypeService.list();
    }

    @ApiOperation("添加分类")
    @DynamicParameters(properties = {
            @DynamicParameter(name = "name", value = "分类名", required = true, dataTypeClass = String.class)
    })
    @PostMapping("/add")
    public ResultData add(@RequestBody GoodsType goodsType){
        return goodsTypeService.add(goodsType);
    }


    @ApiOperation("编辑分类")
    @DynamicParameters(properties = {
            @DynamicParameter(name = "id", value = "分类ID", required = true, dataTypeClass = Integer.class),
            @DynamicParameter(name = "name", value = "分类名", required = true, dataTypeClass = String.class)
    })
    @PostMapping("/edit")
    public ResultData edit(@RequestBody GoodsType goodsType){
        return goodsTypeService.edit(goodsType);
    }



    @ApiOperation("删除")
    @GetMapping("/delete")
    public ResultData delete(@ApiParam(name = "id", value = "分类ID", required = true) Integer id){
        return goodsTypeService.delete(id);
    }


}
